import java.util.Scanner;

public class digitalRoot {

        public static int addDigits(int num) {
            return (num - 1) % 9 + 1;
        }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        int ret = addDigits(i);
        System.out.println(ret);
    }
}
